package com.controller;

import com.entity.Td_tblPartyRelationshipTransfer;
import com.service.inte.MemberServiceInte;
import com.service.inte.Td_tblPartyRelationshipTransferServiceInte;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.sql.Date;
import java.util.List;

@Controller
public class PartyRelationshipTransferController {

    @Autowired
    Td_tblPartyRelationshipTransferServiceInte td_tblPartyRelationshipTransferServiceInte;
    @Autowired
    MemberServiceInte memberServiceInte;

    @GetMapping("turnPartyRelationship")
    public String turnPartyRelationship(HttpServletRequest request,int loginId){
        request.setAttribute("member",memberServiceInte.getByLoginId(loginId));
        return "member/transfer/partyRelationship.html";
    }

    @PostMapping("savePartyrelationship")
    public String save(Td_tblPartyRelationshipTransfer td_tblPartyRelationshipTransfer, BindingResult bindingResult){
        td_tblPartyRelationshipTransfer.setFd_CreateTime(new Date(System.currentTimeMillis()));
        td_tblPartyRelationshipTransferServiceInte.save(td_tblPartyRelationshipTransfer);
        memberServiceInte.updateTransferState(1,td_tblPartyRelationshipTransfer.getFd_LoginID());
        return "member/memberPage.html";
    }

    @GetMapping("turnTransferSearch")
    public String turnTransferSearch(){
        return "member/transfer/transferSearch.html";
    }

    //发起单位
    @PostMapping("finishTransfer")
    @ResponseBody
    public List<Object[]> finishTransfer(String name,int page){
        return td_tblPartyRelationshipTransferServiceInte.getFinishByName(name,149,page);
    }

    //接收单位
    @PostMapping("beFinishTransfer")
    @ResponseBody
    public List<Object[]> beFinishTransfer(String name,int page){
        return td_tblPartyRelationshipTransferServiceInte.getBeFinishByName(name,149,page);
    }

    //接收单位接收未审核结果
    @PostMapping("noFinishTransfer")
    @ResponseBody
    public List<Object[]> noFinishTransfer(String name,int page){
        return td_tblPartyRelationshipTransferServiceInte.getNoFinishByName(name,149,page);
    }

    @GetMapping("turntoTransferList")
    public String turntoTransferList(){
        return "member/transfer/transferList.html";
    }

    //跳转人员接收结果
    @GetMapping("turntoBeTransferList")
    public String turntobeTransferList(){
        return "member/transfer/beTransferList.html";
    }

    //跳转人员未接收列表
    @GetMapping("turntoBeTransferSearch")
    public String turntoBeTransferSearch(){
        return "member/transfer/beTransferSearch.html";
    }

    //跳转到人员接收审核
    @GetMapping("turnBePartyRelationship")
    public String turnBePartyRelationship(HttpServletRequest request,int loginId,int transId){
        request.setAttribute("member",memberServiceInte.getByLoginId(loginId));
        request.setAttribute("trans",td_tblPartyRelationshipTransferServiceInte.getById(transId));
        return "member/transfer/bePartyRelationship.html";
    }

    //人员接收审核
    @PostMapping("beSavePartyrelationship")
    public String beSavePartyrelationship(Td_tblPartyRelationshipTransfer td_tblPartyRelationshipTransfer){
        td_tblPartyRelationshipTransfer.setFd_eduitDate(new Date(System.currentTimeMillis()));
        td_tblPartyRelationshipTransferServiceInte.save(td_tblPartyRelationshipTransfer);
        memberServiceInte.updateBranch(149,"广州供电局",td_tblPartyRelationshipTransfer.getFd_LoginID());
        memberServiceInte.updateTransferState(1,td_tblPartyRelationshipTransfer.getFd_LoginID());
        return "member/memberPage.html";
    }
}
